<?php

error_reporting(E_ALL);

/**
 * ECommerce - class.Controlador.php
 *
 * $Id$
 *
 * This file is part of ECommerce.
 *
 * Automatically generated on 17.11.2011, 10:36:12 with ArgoUML PHP module 
 * (last revised $Date: 2010-01-12 20:14:42 +0100 (Tue, 12 Jan 2010) $)
 *
 * @author firstname and lastname of author, <author@example.org>
 */

if (0 > version_compare(PHP_VERSION, '5')) {
    die('This file was generated for PHP 5');
}

/* user defined includes */
// section 127-0-0-1--2bc61e:12e6b7c56db:-8000:0000000000000DDC-includes begin
require_once('class.Vista.php');
require_once('class.Modelo.php');
// section 127-0-0-1--2bc61e:12e6b7c56db:-8000:0000000000000DDC-includes end

/* user defined constants */
// section 127-0-0-1--2bc61e:12e6b7c56db:-8000:0000000000000DDC-constants begin
// section 127-0-0-1--2bc61e:12e6b7c56db:-8000:0000000000000DDC-constants end

/**
 * Short description of class Controlador
 *
 * @access public
 * @author firstname and lastname of author, <author@example.org>
 */
class Controlador
{
    // --- ASSOCIATIONS ---


    // --- ATTRIBUTES ---

    /**
     * Short description of attribute miVista
     *
     * @access public
     * @var Vista
     */
    public $miVista = null;

    /**
     * Short description of attribute miModelo
     *
     * @access public
     * @var Modelo
     */
    public $miModelo = null;

    // --- OPERATIONS ---

    /**
     * Short description of method Lista
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return mixed
     */
    public function Lista()
    {
        // section 127-0-0-1--2bc61e:12e6b7c56db:-8000:0000000000000DEE begin
       $datos=$this->miModelo->getAllRows();		
	   $this->miVista->Lista($datos);	
        // section 127-0-0-1--2bc61e:12e6b7c56db:-8000:0000000000000DEE end
    }
       
    /**
     * Short description of method Alta
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return mixed
     */
    public function Alta()
    {
        // section 127-0-0-1--2bc61e:12e6b7c56db:-8000:0000000000000DF0 begin
        if (@$_REQUEST[Aceptar]) {
				$this->miModelo->insertRow($_REQUEST);
				$this->Lista();
				}
			else
				$this->miVista->Alta();
        // section 127-0-0-1--2bc61e:12e6b7c56db:-8000:0000000000000DF0 end
    }

    /**
     * Short description of method Editar
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return mixed
     */
    public function Editar()
    {
        // section 127-0-0-1--2bc61e:12e6b7c56db:-8000:0000000000000DF2 begin
        if (@$_REQUEST[Aceptar]) {								// Boton Aceptar
				$this->miModelo->updateRow(@$_REQUEST);		// Graba en el modelo
				$this->Lista();									// Muestra la lista
			}
			else {	
					$datos = $this->miModelo->searchById(@$_REQUEST[id]);
					$this->miVista->Edicion($datos);
			}		
        // section 127-0-0-1--2bc61e:12e6b7c56db:-8000:0000000000000DF2 end
    }

    /**
     * Short description of method Borrar
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return mixed
     */
    public function Borrar()
    {
        // section 127-0-0-1--2bc61e:12e6b7c56db:-8000:0000000000000DF4 begin
        if (@$_REQUEST[Aceptar]) {
				$this->miModelo->deleteRow(@$_REQUEST[id]);
				$this->Lista();
			}
			else {	
				$datos = $this->miModelo->searchById(@$_REQUEST[id]);
				$this->miVista->borrar($datos);
			}	
        // section 127-0-0-1--2bc61e:12e6b7c56db:-8000:0000000000000DF4 end
    }

    /**
     * Short description of method Controlador
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return mixed
     */
    public function Controlador()
    {
        // section 127-0-0-1--2bc61e:12e6b7c56db:-8000:0000000000000DF6 begin
        $this->miModelo = new Modelo();		
		$this->miVista = new Vista();		
		//var_dump($_REQUEST);
		// VISTA 
		if(@$_REQUEST["controlador"]=="" || @$_REQUEST[Cancelar])
		{
			$this->Lista();
		}
		else 
		{
			if(@$_REQUEST["controlador"]=="Buscar") 	
				$this->Buscar();
			if(@$_REQUEST["controlador"]=="nuevo")
				$this->Alta();			
			if(@$_REQUEST["controlador"]=="editar")
				$this->Editar();
			if(@$_REQUEST["controlador"]=="borrar") 
				$this->Borrar();
		}
        // section 127-0-0-1--2bc61e:12e6b7c56db:-8000:0000000000000DF6 end
    }

    /**
     * Short description of method Buscar
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return mixed
     */
    public function Buscar()
    {
        // section -64--88-0-101-54e14bc7:132f9254a1f:-8000:0000000000001482 begin
        $datos=$this->miModelo->getRowsByDescripcion($_REQUEST["descripcion"]);		
		$this->miVista->Lista($datos);
        // section -64--88-0-101-54e14bc7:132f9254a1f:-8000:0000000000001482 end
    }

} /* end of class Controlador */

?>